package biz

import (
	"context"
	"manage/api/class"
	"manage/api/course"
	"manage/api/exam"
	"manage/api/user"

	"github.com/gin-gonic/gin"
	klog "github.com/go-kratos/kratos/v2/log"
)

type APIUseCase struct {
	Repo APIUseRepo
	log  *klog.Helper
}

type Method struct {
	Get    func(ctx *gin.Context)
	Post   func(ctx *gin.Context)
	Put    func(ctx *gin.Context)
	Delete func(ctx *gin.Context)
}

type (
	Option         func(call *APIUseCase)
	UserCallBack   func(context.Context, user.UserServiceClient)
	ExamCallBack   func(context.Context, exam.ExamServiceClient)
	CourseCallBack func(context.Context, course.CourseServiceClient)
	ClassCallBack  func(context.Context, class.ClassServiceClient)
)

type APIUseRepo interface {
	// 用户管理-服务
	User(CallBack UserCallBack)
	// 考试管理-服务
	Exam(CallBack ExamCallBack)
	// 课程管理-服务
	Course(CallBack CourseCallBack)
	// 班级管理-服务
	Class(CallBack ClassCallBack)
	// 学生班级
	StudentClassService
	// 存储Token到Redis
	TokenOperat() Operater
}

type StudentClassService interface {
	// 获取学生班级信息
	GetStudentByClassID(classID string) ([]StudentClass, error)
	// JoinClass 学生加入班级
	JoinClass(request *JoinClassRequest) (*JoinClassResponse, error)
	// LeaveClass 学生退出班级
	LeaveClass(request *LeaveClassRequest) (*LeaveClassResponse, error)
	// RemoveStudentsFromClass 将学生从学生班级中移除
	RemoveStudentsFromClass(classID string) error
}

type Operater interface {
	// 生成Token
	GenTokenToRedis(userId string) (string, error)
	// 校验Token
	CheckTokenInfo(token string) (userId string, _ bool)
}

// NewAPIUseCase 新建一个接口用例
func NewAPIUseCase(us APIUseRepo, logger klog.Logger) *APIUseCase {
	return &APIUseCase{
		Repo: us,
		log:  klog.NewHelper(logger),
	}
}

func (u *APIUseCase) CallGrpc(opts ...Option) {
	for _, opt := range opts {
		opt(u)
	}
}
